
use std::string::String;
use std::net::{TcpStream};
use std::io::{Write, Read, ErrorKind};
use std::thread::sleep;
use std::time::Duration;

fn main() {
    let tcp_addr = "127.0.0.1:9000";
    let mut socket = TcpStream::connect(tcp_addr).unwrap();//连接 server
    socket.write(b"hello client\r\n");  //获取发送网页
    let mut buff:Vec<u8>=Vec::new();
    sleep(Duration::from_secs(1));
    let mut strData= String::new();
    let len= socket.read_to_string(&mut strData).unwrap(); //得到结果
    // let s = String::from_utf8(buff); //转换结果为字符串.
    // println!("len:{}\ndata:{}",len.ok().unwrap(),s.ok().unwrap() );

    println!("data : {}" ,strData.clone() );

    // for i in vec![1;10] {
    //     socket.write(b"hello client");  //获取发送网页
    //     let mut buff:Vec<u8>=Vec::new();
    //     let len = socket.read_to_end(&mut buff); //得到结果
    //     let s = String::from_utf8(buff); //转换结果为字符串.
    //     println!("len:{}\ndata:{}",len.ok().unwrap(),s.ok().unwrap() );
    //
    // }



}
